package org.freedoit.server.dao;

// Generated Oct 11, 2012 3:54:06 PM by Hibernate Tools 3.4.0.CR1

import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import org.freedoit.server.om.TaskType;
import org.freedoit.shared.exception.ServerException;

/**
 * Home object for domain model class TaskType.
 * @see org.freedoit.om.TaskType
 * @author Hibernate Tools
 */
public class TaskTypeDAO {

	//private static final Log log = LogFactory.getLog(TaskTypeDAO.class);

	private final PersistenceManagerFactory pmFactory = DAOFactory.getPersistenceManagerFactory();

	public void persist(TaskType taskType) {
		//log.debug("persisting TaskType instance");
		PersistenceManager pm = pmFactory.getPersistenceManager();
		try {
			pm.makePersistent(taskType);
			//log.debug("persist successful");
		} catch (RuntimeException re) {
			//log.error("persist failed", re);
			throw new ServerException(re);
		} finally {
			pm.close();
		}
	}

	public void delete(TaskType taskType) {
		//log.debug("deleting TaskType instance");
		PersistenceManager pm = pmFactory.getPersistenceManager();
		try {
			pm.currentTransaction().begin();
			// We don't have a reference to the selected Product.
			// So we have to look it up first,
			taskType = pm.getObjectById(TaskType.class, taskType.getTaskTypeId());
			pm.deletePersistent(taskType);

			pm.currentTransaction().commit();
			//log.debug("delete successful");
		} catch (RuntimeException re) {
			//log.error("delete failed", re);
			throw new ServerException(re);
		} finally {
			pm.close();
		}
	}

	public void update(TaskType taskType) {
		//log.debug("updating TaskType instance");
		PersistenceManager pm = pmFactory.getPersistenceManager();
		try {
			pm.currentTransaction().begin();
			pm.makePersistent(taskType);
			pm.currentTransaction().commit();
			//log.debug("update successful");
		} catch (RuntimeException re) {
			//log.error("update failed", re);
			throw new ServerException(re);
		} finally {
			pm.close();
		}
	}

	public TaskType findById(Long id) {
		//log.debug("getting TaskType instance with id: " + id);
		PersistenceManager pm = pmFactory.getPersistenceManager();
		try {
			TaskType instance = pm.getObjectById(TaskType.class, id);
			if (instance == null) {
				//log.debug("get successful, no instance found");
			} else {
				//log.debug("get successful, instance found");
			}
			return instance;
		} catch (RuntimeException re) {
			//log.error("get failed", re);
			throw new ServerException(re);
		} finally {
			pm.close();
		}
	}
}
